import time
from functools import wraps


def metric(fun):
    @wraps(fun)
    def wrapper(*args, **kwargs):
        # 开始计时
        start_time = time.time()
        result = fun(*args, **kwargs)
        # 计时结束
        end_time = time.time()
        # 输出
        print('[{0}]耗时：{1:4f}s'.format(fun.__name__, end_time - start_time))
        return result

    return wrapper


@metric
# 测试用代码
def test_method(max):
    count = 0
    arr_a = range(1, max)
    arr_b = range(1, max)
    for a in arr_a:
        for b in arr_b:
            count += a * b
    return count


# 入口
if __name__ == '__main__':
    print(test_method(5000))
